﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestByWire.Tutorial.Domain;

namespace TestByWire.Tutorial
{
	[TestClass]
	[UseAdditionalTestTarget(typeof(IDataLayer), typeof(DataLayer))]
	public class MultipleTestTargets : TestTarget<LogicLayer>
	{
		[TestMethod]
		public void DataLayerMustBeRealType()
		{
			string correlatedValue = When.Calling.Execute();

			Assert.AreEqual(DataLayer.UniqueString, correlatedValue);
		}

		[TestMethod]
		[UseAdditionalTestTarget(typeof(ILog), typeof(RealLog))]
		public void LogMustAlsoBeRealType()
		{
			When.Calling.Execute();

			Assert.AreEqual("Executing...", RealLog.WrittenMessage);
		}

		[TestMethod]
		[UseAdditionalTestTarget(typeof(IDataLayer), typeof(OtherDataLayer))]
		public void OtherDataLayerMustBeUsed()
		{
			string correlatedValue = When.Calling.Execute();

			Assert.AreEqual(OtherDataLayer.UniqueString, correlatedValue);
		}

		[TestMethod]
		[UseAdditionalTestTarget(typeof(ILog), typeof(RealLog))]
		[UseAdditionalTestTarget(typeof(IDataLayer), typeof(OtherDataLayer))]
		public void OtherDataLayerAndRealLogMustBeUsed()
		{
			string correlatedValue = When.Calling.Execute();

			Assert.AreEqual(OtherDataLayer.UniqueString, correlatedValue);
			Assert.AreEqual("Executing...", RealLog.WrittenMessage);
		}

		[TestMethod]
		[UseAdditionalTestTarget(typeof(ILog), typeof(RealLog))]
		[UseAdditionalTestTarget(typeof(IDataLayer), typeof(OtherDataLayer))]
        [UseStubLateBound(typeof(IDataLayer), "_dataLayer")]
		public void ExecuteMustThrowBecauseStubBeingLateBoundIsAlreadyInUseAsAdditionalTestTarget()
		{
            When.Calling.Execute();

			Then<IDataLayer>.Should("_dataLayer", x=>x.Execute());
		}
	}
}
